package com.ddv.www.sqlcipher;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import com.ddv.www.sqlcipher.dbhelper.DBCipherManager;

import butterknife.Bind;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {


    @Bind(R.id.add)
    Button add;
    @Bind(R.id.add_no_be)
    Button addNoBe;
    @Bind(R.id.add_have_be)
    Button addHaveBe;
    @Bind(R.id.delete)
    Button delete;
    @Bind(R.id.delete_some)
    Button deleteSome;
    @Bind(R.id.updata)
    Button updata;
    @Bind(R.id.query_for_condition)
    Button queryForCondition;
    @Bind(R.id.query_all)
    Button queryAll;
    @Bind(R.id.delete_all)
    Button deleteAll;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        add.setOnClickListener(this);
        addNoBe.setOnClickListener(this);
        addHaveBe.setOnClickListener(this);
        delete.setOnClickListener(this);
        deleteSome.setOnClickListener(this);
        updata.setOnClickListener(this);
        queryForCondition.setOnClickListener(this);
        queryAll.setOnClickListener(this);
        deleteAll.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.add:
                //插入数据
                for (int i = 0; i < 10; i++) {
                    DBCipherManager.getInstance(MainActivity.this).insertData(String.valueOf(i), i);
                }
                break;
            case R.id.add_no_be://未开启事务批量插入
                DBCipherManager.getInstance(MainActivity.this).insertDatasByNomarl(10);
                break;
            case R.id.add_have_be://测试开启事务批量插入
                DBCipherManager.getInstance(MainActivity.this).insertDatasByTransaction(10);
                break;
            case R.id.delete:
                //删除数据
                DBCipherManager.getInstance(MainActivity.this).deleteData(String.valueOf(5));
                break;
            case R.id.delete_some:
                //多个字段删除数据
                DBCipherManager.getInstance(MainActivity.this).deleteData(String.valueOf(6), 6);
                break;
            case R.id.updata:
                //更新数据
                DBCipherManager.getInstance(MainActivity.this).updateData(String.valueOf(3), 3);
                break;
            case R.id.query_for_condition://指定条件查询数据
                DBCipherManager.getInstance(MainActivity.this).queryDatas(String.valueOf(2));
                break;
            case R.id.query_all:
                //查询数据
                DBCipherManager.getInstance(MainActivity.this).queryDatas();
                break;
            case R.id.delete_all:
                //清空数据
                DBCipherManager.getInstance(MainActivity.this).deleteDatas();
                break;
        }
    }
}
